<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="vue.min.js"></script>
</head>
<style>
    *{
        text-align: center;
    }
</style>
<body>
    <div id="app">
        <!--子父控件使用的过程中一定要包含在一个标签内，否则无效。-->
        <div>
            <!--引用父类窗体-->
            <select-info :list="list"></select-info>
        </div>
    </div>
    <!--父窗体-->
    <template id="fu-comp">
        <div>
            <h1>员工信息表</h1>
            <input type="text" v-model="select" placeholder="请输入查询内容">
            <hr/>
            <!--引用子类窗体-->
            <list-table :show="filterlist"></list-table>
        </div>
    </template>
    <template id="zi-comp">
        <div>
            <table class="table table-hover">
                <tr class="info">
                    <td>编号</td>
                    <td>姓名</td>
                    <td>年龄</td>
                    <td>地址</td>
                </tr>
                <tr v-for="item in show">
                    <td>{{item.id}}</td>
                    <td>{{item.name}}</td>
                    <td>{{item.age}}</td>
                    <td>{{item.address}}</td>
                </tr>
            </table>
        </div>
    </template>
    <script>
        new Vue({
            el: "#app",
            data: {
                list: [{
                    id: 1,
                    name: "秋雅",
                    age: 17,
                    address: "西红柿第一中学"
                }, {
                    id: 2,
                    name: "袁华",
                    age: 17,
                    address: "西红柿区长家"
                }]
            },
            components: {
                "select-info": {
                    props: ["list"],
                    data: function() {
                        return {
                            select: ""
                        }
                    },
                    template: "#fu-comp",
                    components: {
                        "list-table": {
                            props: ["show"],
                            template: "#zi-comp"
                        }
                    },
                    computed: {
                        filterlist: function() {
                            var _this = this;
                            return _this.list.filter(function(val) {
                                console.log(val.name);
                                return val.name.indexOf(_this.select) != -1;
                            });
                        }
                    }
                }
            }
        });
    </script>
</body>

</html>